var x0=0,y0=0,x1=0,y1=0;
var index=10000;
var moveable=false;
var offx=6,offy=6;
var mWin_id=1;

//??????
function mWin(id,width,height,left,top,title,html,isHidden) {
  index+=2;
  this.id       = id;
  this.width    = width;
  this.height   = height;
  this.left     = left;
  this.top      = top;
  this.zIndex   = index;
  this.title    = title;
  this.content  = html;
  this.obj      = null;
  this.bulid    = function bulid() {
    var str=''
    +'<div id="mWin'+this.id+'" style="position:absolute; width:'+this.width+'px; z-index:'+this.zIndex+'; left: '+this.left+'px; top: '+this.top+'px;" onmousedown="getFocus(this)">\n'
    +'          <table width="'+this.weight+'" border="0" cellspacing="0" cellpadding="0" style="position:absolute;">\n'
    +'            <tr align="center" onmousedown="startDrag(this)"  onmouseup="stopDrag(this)" onmousemove="drag(this)" ondblclick="min(this)">\n'
    +'              <td width="12" height="38" align="left" background="../images/div_topBg.gif"><img src="../images/div_topLeft.gif" width="12" height="38"></td>\n'
    +'              <td background="../images/div_topBg.gif" width="'+this.width+'" height="38" align="left">\n'
    +'                <table width="100%" id="mSub'+this.id+'"  border="0" cellspacing="0" cellpadding="0">\n'
    +'                  <tr>\n'
    +'                    <td width="5%" align="left"><img src="../images/div_topPic.gif" width="11" height="38"></td>\n'
    +'                    <td width="81%" class="TFont2" style="padding-top:2px" align="left">'+this.title+'</td>\n'
    +'                    <td width="14%" align="right"><a onclick="mWin'+this.id+'.style.display=\'none\';" style="cursor:hand;"><img src="../images/B_close_1.gif" name="Image47" width="16" height="16" border="0" onMouseOut="this.src=\'../images/B_close_1.gif\'" onMouseOver="this.src=\'../images/B_close_2.gif\'"></a></td>\n'
    +'                  </tr>\n'
    +'              </table></td>\n'
    +'              <td background="../images/div_topBg.gif" width="15" height="38" align="right"><img src="../images/div_topRight.gif" width="14" height="38"></td>\n'
    +'            </tr>\n'
    +'            <tr>\n'
    +'              <td height="126" bgcolor="#FFFFFF" class="divBg1">&nbsp;</td>\n'
    +'              <td align="left" valign="top" bgcolor="#FFFFFF">\n<div id="mWinScroll" style="height:'+(this.height - 20) + 'px;width:100%;overflow-y:auto;">'+html+'</div></td>\n'
    +'              <td bgcolor="#FFFFFF" class="divBg2">&nbsp;</td>\n'
    +'            </tr>\n'
    +'            <tr>\n'
    +'              <td background="../images/div_bottomBg.gif" align="left"><img src="../images/div_bottomLeft.gif" width="14" height="13"></td>\n'
    +'              <td background="../images/div_bottomBg.gif">&nbsp;</td>\n'
    +'              <td background="../images/div_bottomBg.gif" align="right"><img src="../images/div_bottomRight.gif" width="13" height="13"></td>\n'
    +'            </tr>\n'
    +'          </table>\n'
    +'       </div>\n';
    document.body.insertAdjacentHTML("beforeEnd",str);
  }

  this.close=function close(){
    eval('mWin'+this.id+'.style.display="none"');
  }
	
  this.open=function open() {
	eval('mWin'+this.id+'.style.display="block"');
  }
	
  this.bulid();
}
//???????
function startDrag(obj)
{
	if(event.button==1)
	{
		//????????
		obj.setCapture();
		//??????;
    document.getElementById('mWinScroll').style.overflowY = 'hidden';
		var win = obj.parentNode.parentNode.parentNode;
		///var sha = win.nextSibling;
		//????????????;
		x0 = event.clientX;
		y0 = event.clientY;
		x1 = parseInt(win.style.left);
		y1 = parseInt(win.style.top);
		//??????;
		normal = obj.style.backgroundColor;
		//??????;
		//obj.style.backgroundColor = hover;
		//win.style.borderColor = hover;
		//obj.nextSibling.style.color = hover;
		///sha.style.left = x1 + offx;
		///sha.style.top  = y1 + offy;
		moveable = true;
	}
}
//???;
function drag(obj)
{
	if(moveable)
	{
		var win = obj.parentNode.parentNode.parentNode;
		///var sha = win.nextSibling;
		win.style.left = x1 + event.clientX - x0;
		win.style.top  = y1 + event.clientY - y0;
		///sha.style.left = parseInt(win.style.left) + offx;
		///sha.style.top  = parseInt(win.style.top) + offy;
	}
}
//??????;
function stopDrag(obj)
{
	if(moveable)
	{
		var win = obj.parentNode.parentNode.parentNode;
		var sha = win.nextSibling;
		var msg = obj.nextSibling;
		win.style.borderColor     = normal;
		obj.style.backgroundColor = normal;
		msg.style.color           = normal;
		//sha.style.left = obj.parentNode.style.left;
		//sha.style.top  = obj.parentNode.style.top;
        document.getElementById('mWinScroll').style.overflowY='auto';
		obj.releaseCapture();
		moveable = false;
	}
}
//??????;
function getFocus(obj)
{
	if(obj.style.zIndex!=index)
	{
		index = index + 2;
		var idx = index;
		obj.style.zIndex=idx;
		///obj.nextSibling.style.zIndex=idx-1;
	}
}
//?????;
function min(obj)
{
  obj.nextSibling.style.display=(obj.nextSibling.style.display=='none')?'block':'none';
  //obj.nextSibling.nextSibling.style.display=(obj.nextSibling.nextSibling.style.display=='none')?'block':'none';
}